<?php

declare(strict_types = 1 );
namespace app\api\controller;


use app\api\validate\User;
use app\BaseController;

class Login extends BaseController
{
    public function index() : object {
        $phone_number = $this->request->param("phone_number","","trim");
        $code = input("param.code",0,"intval");
        $type = input("param.code",0,"intval");
        // 参数校验
        $data = [
            'phone_number' => $phone_number,
            'code' => $code,
            'type' => $type
        ];
        $validate = new User();
        if(!$validate->scene('login')->check($data)){
//            throw new \think\Exception("不存在验证码",-1009);
            return  show(config('status.error'),$validate->getError());
        }
        $result = (new \app\common\business\User())->login($data);
        if($result){
            return  show(config('status.success'),'登录成功',$result);
        }
        return  show(config('status.error'),'登录失败');
    }
}